﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace libCommonTools
{
    public class clsTimerDelay
    {
        private System.Windows.Forms.Timer timer1;
        private bool bolOngoing = false;

        public bool get_CheckStoped
        {
            get
            {
                return bolOngoing;
            }
            set
            {
                bolOngoing = value;
            }
        }

        public void RevokeQueryTimer()
        {
            if (timer1 != null)
            {
                timer1.Stop();
                timer1.Tick -= queryTimer_Tick;
                timer1 = null;
                get_CheckStoped = false;
            }
        }

        public void RestartQueryTimer()
        {
            // Start or reset a pending query
            if (timer1 == null)
            {
                timer1 = new System.Windows.Forms.Timer { Enabled = true, Interval = 200 };
                timer1.Tick += queryTimer_Tick;
                get_CheckStoped = false;
            }
            else
            {
                timer1.Stop();
                timer1.Start();
                get_CheckStoped = false;
            }
        }

        private void queryTimer_Tick(object sender, EventArgs e)
        {
            // Stop the timer so it doesn't fire again unless rescheduled
            RevokeQueryTimer();
            get_CheckStoped = true;
        }
    }
}
